/**
 * @Title: update-source-modal.js
 * @Description: update-source-modal
 * @author: Fanchao
 * @date: 2021/2/4 1:42 上午
 * @version V1.0
 */
import React from 'react';
import { Form, InputNumber, Modal } from 'antd';
import { connect } from 'umi';

const layout = {
    labelCol: { span: 4 },
    wrapperCol: { span: 20 },
};
const UpdateSourceModal = ({ classEvaluations: { itemData }, dispatch, updateSourceFlag }) => {
    const [form] = Form.useForm();
    form.setFieldsValue({
        centerScore: itemData.centerScore,
        schoolExpertScore: itemData.schoolExpertScore,
        teachSectionScore: itemData.teachSectionScore,
    });
    return (
        <Modal
            title="修改评分"
            visible={updateSourceFlag}
            // width="900px"
            onOk={() => {
                form.validateFields().then(values => {
                    values.historyEvaluateTeacherObjectId = itemData.historyEvaluateTeacherObjectId;
                    dispatch({
                        type: 'classEvaluations/updateEvaluateResultScore',
                        payload: values,
                        callback: (result) => {
                            if (result) {
                                form.resetFields();
                                dispatch({
                                    type: 'classEvaluations/setItemData',
                                    payload: {},
                                });
                                dispatch({
                                    type: 'classEvaluations/setUpdateSourceFlag',
                                    payload: false,
                                });
                                dispatch({
                                    type: 'classEvaluations/getHistoryDataSource',
                                    payload: {
                                        reqPageInfo: {
                                            pageNumber: 1,
                                            pageSize: 10,
                                        },
                                    },
                                });
                            }
                        },
                    });

                }).catch(info => {
                });
            }}
            onCancel={() => {
                form.resetFields();
                dispatch({
                    type: 'classEvaluations/setUpdateSourceFlag',
                    payload: false,
                });
            }}
        >
            <Form
                {...layout}
                layout="horizontal"
                form={form}
                name="basic"
                // 表单默认值，只有初始化以及重置时生效 莫用
                initialValues={{
                    // name: itemData.name
                }}
            >
                <Form.Item
                    label="校专家评分"
                    name="schoolExpertScore"
                    // rules={[{ required: true, message: '必填' }]}
                >
                    <InputNumber placeholder="请输入校专家评分" style={{ width: '100%' }}/>
                </Form.Item>
                <Form.Item
                    label="部系评分"
                    name="centerScore"
                    // rules={[{ required: true, message: '必填' }]}
                >
                    <InputNumber placeholder="请输入部系评分" style={{ width: '100%' }}/>
                </Form.Item>
                <Form.Item
                    label="教研室评分"
                    name="teachSectionScore"
                    // rules={[{ required: true, message: '必填' }]}
                >
                    <InputNumber placeholder="请输入教研室评分" style={{ width: '100%' }}/>
                </Form.Item>
            </Form>
        </Modal>
    );
};

export default connect(({ classEvaluations, dispatch, loading }) => ({
    classEvaluations,
    dispatch,
    loading: loading.effects['classEvaluations/getHistoryDataSource'],
}))(UpdateSourceModal);
